package lty.pritace.topics;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.apache.activemq.ActiveMQConnectionFactory;

/**
 * 接受消息非持久化
 * 
 * @author lty
 *
 */
public class NoPersisternceQueueReceiver {
	public static void main(String[] args) throws Exception {
		ConnectionFactory cf = new ActiveMQConnectionFactory("tcp://192.168.233.128:61616");
		Connection connection = cf.createConnection();
		connection.start();

		final Session session = connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
		Destination destination = session.createTopic("topic1");
		MessageConsumer consumer = session.createConsumer(destination);
		Message message = consumer.receive();
		while (message != null) {
			// TextMessage message = (TextMessage) consumer.receive();
			TextMessage txt = (TextMessage) message;
			System.out.println("收到消息1213：" + txt.getText());
			message = consumer.receive(1000l);
		}
		session.commit();
		session.close();
		connection.close();
	}
}
